package com.yukh.test.javabase.thread.concurrent.demo1;

public class Consumer extends Thread {
	ProductList products = ProductList.getInstance();

	public void run() {
		while (true) {
			synchronized (products) {
				try {
					products.wait(); 			// Wait for lock
					Product product = null;
					if (!(products.isEmpty()))
						product = products.take();
					else
						System.out.println("List is empty");
					System.out.println("Consumed product " + product.getId()); // Get
																			   // the
																			   // lock
				} catch (InterruptedException ex) {
					ex.printStackTrace();
				}
			} // Release the lock
		}
	}
}
